/**
 * Created by mill on 2017/11/19.
 */
import React , {Component} from 'react';
import {render} from 'react-dom';
import 'isomorphic-fetch'


class UserGist extends Component{
    constructor(props){
        super(props)
        this.state={liked: false};
        this.handleClick = this.handleClick.bind(this);
    }
    handleClick(e){
        this.setState({liked: !this.state.liked});
        let _this=this;
        fetch(this.props.sourcs)
            .then((respons)=>{
                return  respons.json().then((data)=>{
                    _this.setState({atime:data[0].created_at});
                    return data;
                })
            }).then((dd)=>{

            let txt=dd.map((item,index)=>{
                return <tr key={index}><td>{item.created_at}</td></tr>
            });
            this.setState({aa:txt});
        });
    }
    componentDidMount(){

    }
    render() {
       var text = this.state.liked ? 'like' : 'haven\'t liked';
    return (
      <div onClick={this.handleClick}>
        You {text} Click   to toggle.
          <table>
              <tbody>
              {this.state.aa}
              </tbody>

          </table>
      </div>

    );
    }
}
render(
    <UserGist sourcs="https://api.github.com/users/octocat/gists"/>,
    document.querySelector("#tajax")
);

